﻿using MediatR;
using Traceability.Commont.Domains;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;

namespace U.Enterprise.Api.Applications.GETSection
{
    public class SectionCreateHandler : IRequestHandler<SectionCreateCommond, Resqults>
    {


        private readonly IBateRepository<Department> _Departmen;

        public SectionCreateHandler(IBateRepository<Department> departmen)
        {
            _Departmen = departmen;
        }

        /// <summary>
        /// 部门添加
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Resqults> Handle(SectionCreateCommond request, CancellationToken cancellationToken)
        {
            var list = new Resqults() { Code = 0 };
            var query = new Department()
            {
                Departmentid = request.Departmentid,
                DepartmentName = request.DepartmentName,
                Levelid = request.Levelid,
                Typeid = request.Typeid,
            };
            var hb = await _Departmen.Add(query);
            if(hb != null)
            {
                list.Messges = "新增成功";
                list.Code = 1;
            }
            return list;
        }
    }
}
